#include "armintcontrol.h"
#include "s3c2410.h"
extern quint32 R[16];
extern quint32 R_FIQ[16];
extern quint32 R_IRQ[16];
#define PC R[15]
extern quint8 SFR_MEM[0X60000000-0X48000000];
extern quint32 CPSR;//程序状态寄存器N Z C V Q DNM(RAZ) I F T M4 M3 M2 M1 M0
extern quint32 SPSR_FIQ;//程序状态保存寄存器
extern quint32 SPSR_IRQ;//程序状态保存寄存器
ArmIntControl::ArmIntControl(){}
void ArmIntControl::execcontrol(){
    static bool isinterrupt=false;
    quint32 SUBSRCPND=0,INTSUBMSK=0,SRCPND=0,INTMSK=0,INTMOD=0,PRIORITY=0,INTPND=0,INTOFFSET=0;
    memcontrol(rSUBSRCPND,true,SUBSRCPND,4);
    memcontrol(rINTSUBMSK,true,INTSUBMSK,4);

    memcontrol(rSRCPND,true,SRCPND,4);
    memcontrol(rINTMSK,true,INTMSK,4);

    memcontrol(rINTMOD,true,INTMOD,4);
    memcontrol(rPRIORITY,true,PRIORITY,4);

    memcontrol(rINTPND,true,INTPND,4);
    if((SUBSRCPND&0x7FFF)&&SRCPND&&INTPND)isinterrupt=false;
    if(isinterrupt)return;
    SUBSRCPND=(SUBSRCPND&(~INTSUBMSK))&0B111111111111111;
    if(SUBSRCPND&0B111){SRCPND=(SRCPND|0B10000000000000000000000000000);}
    if(SUBSRCPND&0B111000){SRCPND=(SRCPND|0B100000000000000000000000);}
    if(SUBSRCPND&0B111000000){SRCPND=(SRCPND|0B1000000000000000);}
    if(SUBSRCPND&0B11000000000){SRCPND=(SRCPND|0x80000000);}
    if(SUBSRCPND&0B1100000000000){SRCPND=(SRCPND|0B100000);}
    if(SUBSRCPND&0B110000000000000){SRCPND=(SRCPND|0x100);}
    memcontrol(rSRCPND,false,SRCPND,4);
    quint32 FIQ=(SRCPND&INTMOD);//FIQ
    if(FIQ){
       R_FIQ[14]=PC;
       SPSR_FIQ=CPSR;
       CPSR=CPSR&0XFFFFFFF1;
       CPSR=CPSR|0B10001;
       PC=0X01C;
       return;
    }
    quint32 IRQ=((SRCPND&~(INTMOD))&(~INTMSK));//IRQ
    if(IRQ==0)return;
    if(PRIORITY&1){//0组轮转
        switch (PRIORITY&0B110000000){
        case 0B000000000://1234
            if(IRQ&0B0001){IRQ=IRQ&0XFFFFFFF1;PRIORITY=PRIORITY|0B010000000;PRIORITY=PRIORITY&0XFFFFFEFF;break;}
            if(IRQ&0B0010){IRQ=IRQ&0XFFFFFFF2;PRIORITY=PRIORITY&0XFFFFFF7F;PRIORITY=PRIORITY|0B100000000;break;}
            if(IRQ&0B0100){IRQ=IRQ&0XFFFFFFF4;PRIORITY=PRIORITY|0B110000000;break;}
            if(IRQ&0B1000){IRQ=IRQ&0XFFFFFFF8;PRIORITY=PRIORITY&0XFFFFFE7F;break;}
            break;
        case 0B010000000://2341
            if(IRQ&0B0010){IRQ=IRQ&0XFFFFFFF2;PRIORITY=PRIORITY&0XFFFFFF7F;PRIORITY=PRIORITY|0B100000000;break;}
            if(IRQ&0B0100){IRQ=IRQ&0XFFFFFFF4;PRIORITY=PRIORITY|0B110000000;break;}
            if(IRQ&0B1000){IRQ=IRQ&0XFFFFFFF8;PRIORITY=PRIORITY&0XFFFFFE7F;break;}
            if(IRQ&0B0001){IRQ=IRQ&0XFFFFFFF1;PRIORITY=PRIORITY|0B010000000;PRIORITY=PRIORITY&0XFFFFFEFF;break;}
            break;
        case 0B100000000://3412
            if(IRQ&0B0100){IRQ=IRQ&0XFFFFFFF4;PRIORITY=PRIORITY|0B110000000;break;}
            if(IRQ&0B1000){IRQ=IRQ&0XFFFFFFF8;PRIORITY=PRIORITY&0XFFFFFE7F;break;}
            if(IRQ&0B0001){IRQ=IRQ&0XFFFFFFF1;PRIORITY=PRIORITY|0B010000000;PRIORITY=PRIORITY&0XFFFFFEFF;break;}
            if(IRQ&0B0010){IRQ=IRQ&0XFFFFFFF2;PRIORITY=PRIORITY&0XFFFFFF7F;PRIORITY=PRIORITY|0B100000000;break;}
            break;
        case 0B110000000://4123
            if(IRQ&0B1000){IRQ=IRQ&0XFFFFFFF8;PRIORITY=PRIORITY&0XFFFFFE7F;break;}
            if(IRQ&0B0001){IRQ=IRQ&0XFFFFFFF1;PRIORITY=PRIORITY|0B010000000;PRIORITY=PRIORITY&0XFFFFFEFF;break;}
            if(IRQ&0B0010){IRQ=IRQ&0XFFFFFFF2;PRIORITY=PRIORITY&0XFFFFFF7F;PRIORITY=PRIORITY|0B100000000;break;}
            if(IRQ&0B0100){IRQ=IRQ&0XFFFFFFF4;PRIORITY=PRIORITY|0B110000000;break;}
            break;
        default:
            break;
        }
    }else{
        switch (PRIORITY&0B110000000){
        case 0B000000000://1234
            if(IRQ&0B0001){IRQ=IRQ&0XFFFFFFF1;break;}
            if(IRQ&0B0010){IRQ=IRQ&0XFFFFFFF2;break;}
            if(IRQ&0B0100){IRQ=IRQ&0XFFFFFFF4;break;}
            if(IRQ&0B1000){IRQ=IRQ&0XFFFFFFF8;break;}
            break;
        case 0B010000000://2341
            if(IRQ&0B0010){IRQ=IRQ&0XFFFFFFF2;break;}
            if(IRQ&0B0100){IRQ=IRQ&0XFFFFFFF4;break;}
            if(IRQ&0B1000){IRQ=IRQ&0XFFFFFFF8;break;}
            if(IRQ&0B0001){IRQ=IRQ&0XFFFFFFF1;break;}
            break;
        case 0B100000000://3412
            if(IRQ&0B0100){IRQ=IRQ&0XFFFFFFF4;break;}
            if(IRQ&0B1000){IRQ=IRQ&0XFFFFFFF8;break;}
            if(IRQ&0B0001){IRQ=IRQ&0XFFFFFFF1;break;}
            if(IRQ&0B0010){IRQ=IRQ&0XFFFFFFF2;break;}
            break;
        case 0B110000000://4123
            if(IRQ&0B1000){IRQ=IRQ&0XFFFFFFF8;break;}
            if(IRQ&0B0001){IRQ=IRQ&0XFFFFFFF1;break;}
            if(IRQ&0B0010){IRQ=IRQ&0XFFFFFFF2;break;}
            if(IRQ&0B0100){IRQ=IRQ&0XFFFFFFF4;break;}
            break;
        default:
            break;
        }
    }
    if(PRIORITY&10){//1组轮转 10 9
        switch (PRIORITY&0B11000000000) {
        case 0B00000000000://0 1 2 3 4 5
            if(IRQ&0B0000010000){IRQ=IRQ&0XFFFFFC1F;break;}

            if(IRQ&0B0000100000){IRQ=IRQ&0XFFFFFC2F;PRIORITY=PRIORITY|0B01000000000;PRIORITY=PRIORITY|0XFFFFFBFF;break;}
            if(IRQ&0B0001000000){IRQ=IRQ&0XFFFFFC4F;PRIORITY=PRIORITY&0XFFFFFDFF;PRIORITY=PRIORITY|0B10000000000;break;}
            if(IRQ&0B0010000000){IRQ=IRQ&0XFFFFFC8F;PRIORITY=PRIORITY|0B11000000000;break;}
            if(IRQ&0B0100000000){IRQ=IRQ&0XFFFFFD0F;PRIORITY=PRIORITY&0XFFFFF9FF;break;}

            if(IRQ&0B1000000000){IRQ=IRQ&0XFFFFFE0F;break;}
            break;
        case 0B01000000000://0  2 3 4 1 5
            if(IRQ&0B0000010000){IRQ=IRQ&0XFFFFFC1F;break;}

            if(IRQ&0B0001000000){IRQ=IRQ&0XFFFFFC4F;PRIORITY=PRIORITY&0XFFFFFDFF;PRIORITY=PRIORITY|0B10000000000;break;}
            if(IRQ&0B0010000000){IRQ=IRQ&0XFFFFFC8F;PRIORITY=PRIORITY|0B11000000000;break;}
            if(IRQ&0B0100000000){IRQ=IRQ&0XFFFFFD0F;PRIORITY=PRIORITY&0XFFFFF9FF;break;}
            if(IRQ&0B0000100000){IRQ=IRQ&0XFFFFFC2F;PRIORITY=PRIORITY|0B01000000000;PRIORITY=PRIORITY|0XFFFFFBFF;break;}

            if(IRQ&0B1000000000){IRQ=IRQ&0XFFFFFE0F;break;}
            break;
        case 0B10000000000://0 3 4 1 2 5
            if(IRQ&0B0000010000){IRQ=IRQ&0XFFFFFC1F;break;}

            if(IRQ&0B0010000000){IRQ=IRQ&0XFFFFFC8F;PRIORITY=PRIORITY|0B11000000000;break;}
            if(IRQ&0B0100000000){IRQ=IRQ&0XFFFFFD0F;PRIORITY=PRIORITY&0XFFFFF9FF;break;}
            if(IRQ&0B0000100000){IRQ=IRQ&0XFFFFFC2F;PRIORITY=PRIORITY|0B01000000000;PRIORITY=PRIORITY|0XFFFFFBFF;break;}
            if(IRQ&0B0001000000){IRQ=IRQ&0XFFFFFC4F;PRIORITY=PRIORITY&0XFFFFFDFF;PRIORITY=PRIORITY|0B10000000000;break;}

            if(IRQ&0B1000000000){IRQ=IRQ&0XFFFFFE0F;break;}
            break;
        case 0B11000000000:// 0 4 1 2 3 5
            if(IRQ&0B0000010000){IRQ=IRQ&0XFFFFFC1F;break;}

            if(IRQ&0B0100000000){IRQ=IRQ&0XFFFFFD0F;PRIORITY=PRIORITY&0XFFFFF9FF;break;}
            if(IRQ&0B0000100000){IRQ=IRQ&0XFFFFFC2F;PRIORITY=PRIORITY|0B01000000000;PRIORITY=PRIORITY|0XFFFFFBFF;break;}
            if(IRQ&0B0001000000){IRQ=IRQ&0XFFFFFC4F;PRIORITY=PRIORITY&0XFFFFFDFF;PRIORITY=PRIORITY|0B10000000000;break;}
            if(IRQ&0B0010000000){IRQ=IRQ&0XFFFFFC8F;PRIORITY=PRIORITY|0B11000000000;break;}

            if(IRQ&0B1000000000){IRQ=IRQ&0XFFFFFE0F;break;}
            break;
        default:
            break;
        }
    }else{
        switch (PRIORITY&0B11000000000) {
        case 0B00000000000://0 1 2 3 4 5
            if(IRQ&0B0000010000){IRQ=IRQ&0XFFFFFC1F;break;}

            if(IRQ&0B0000100000){IRQ=IRQ&0XFFFFFC2F;break;}
            if(IRQ&0B0001000000){IRQ=IRQ&0XFFFFFC4F;break;}
            if(IRQ&0B0010000000){IRQ=IRQ&0XFFFFFC8F;break;}
            if(IRQ&0B0100000000){IRQ=IRQ&0XFFFFFD0F;break;}

            if(IRQ&0B1000000000){IRQ=IRQ&0XFFFFFE0F;break;}
            break;
        case 0B01000000000://0  2 3 4 1 5
            if(IRQ&0B0000010000){IRQ=IRQ&0XFFFFFC1F;break;}

            if(IRQ&0B0001000000){IRQ=IRQ&0XFFFFFC4F;break;}
            if(IRQ&0B0010000000){IRQ=IRQ&0XFFFFFC8F;break;}
            if(IRQ&0B0100000000){IRQ=IRQ&0XFFFFFD0F;break;}
            if(IRQ&0B0000100000){IRQ=IRQ&0XFFFFFC2F;break;}

            if(IRQ&0B1000000000){IRQ=IRQ&0XFFFFFE0F;break;}
            break;
        case 0B10000000000://0 3 4 1 2 5
            if(IRQ&0B0000010000){IRQ=IRQ&0XFFFFFC1F;break;}

            if(IRQ&0B0010000000){IRQ=IRQ&0XFFFFFC8F;break;}
            if(IRQ&0B0100000000){IRQ=IRQ&0XFFFFFD0F;break;}
            if(IRQ&0B0000100000){IRQ=IRQ&0XFFFFFC2F;break;}
            if(IRQ&0B0001000000){IRQ=IRQ&0XFFFFFC4F;break;}

            if(IRQ&0B1000000000){IRQ=IRQ&0XFFFFFE0F;break;}
            break;
        case 0B11000000000:// 0 4 1 2 3 5
            if(IRQ&0B0000010000){IRQ=IRQ&0XFFFFFC1F;break;}

            if(IRQ&0B0100000000){IRQ=IRQ&0XFFFFFD0F;break;}
            if(IRQ&0B0000100000){IRQ=IRQ&0XFFFFFC2F;break;}
            if(IRQ&0B0001000000){IRQ=IRQ&0XFFFFFC4F;break;}
            if(IRQ&0B0010000000){IRQ=IRQ&0XFFFFFC8F;break;}

            if(IRQ&0B1000000000){IRQ=IRQ&0XFFFFFE0F;break;}
            break;
        default:
            break;
        }
    }
    if(PRIORITY&100){//2组轮转
        switch (PRIORITY&0B1100000000000) {
        case 0B0000000000000:
            if(IRQ&0B0000010000000000){IRQ=IRQ&0XFFFF07FF;break;}

            if(IRQ&0B0000100000000000){IRQ=IRQ&0XFFFF0BFF;PRIORITY=PRIORITY|0B0100000000000;PRIORITY=PRIORITY&0XFFFFEFFF;break;}
            if(IRQ&0B0001000000000000){IRQ=IRQ&0XFFFF13FF;PRIORITY=PRIORITY&0XFFFFF7FF;PRIORITY=PRIORITY|0B1000000000000;break;}
            if(IRQ&0B0010000000000000){IRQ=IRQ&0XFFFF23FF;PRIORITY=PRIORITY|0B1100000000000;break;}
            if(IRQ&0B0100000000000000){IRQ=IRQ&0XFFFF43FF;PRIORITY=PRIORITY&0XFFFFE7FF;break;}

            if(IRQ&0B1000000000000000){IRQ=IRQ&0XFFFF83FF;break;}
            break;
        case 0B0100000000000:
            if(IRQ&0B0000010000000000){IRQ=IRQ&0XFFFF07FF;break;}

            if(IRQ&0B0001000000000000){IRQ=IRQ&0XFFFF13FF;PRIORITY=PRIORITY&0XFFFFF7FF;PRIORITY=PRIORITY|0B1000000000000;break;}
            if(IRQ&0B0010000000000000){IRQ=IRQ&0XFFFF23FF;PRIORITY=PRIORITY|0B1100000000000;break;}
            if(IRQ&0B0100000000000000){IRQ=IRQ&0XFFFF43FF;PRIORITY=PRIORITY&0XFFFFE7FF;break;}
            if(IRQ&0B0000100000000000){IRQ=IRQ&0XFFFF0BFF;PRIORITY=PRIORITY|0B0100000000000;PRIORITY=PRIORITY&0XFFFFEFFF;break;}

            if(IRQ&0B1000000000000000){IRQ=IRQ&0XFFFF83FF;break;}
            break;
        case 0B1000000000000:
            if(IRQ&0B0000010000000000){IRQ=IRQ&0XFFFF07FF;break;}

            if(IRQ&0B0010000000000000){IRQ=IRQ&0XFFFF23FF;PRIORITY=PRIORITY|0B1100000000000;break;}
            if(IRQ&0B0100000000000000){IRQ=IRQ&0XFFFF43FF;PRIORITY=PRIORITY&0XFFFFE7FF;break;}
            if(IRQ&0B0000100000000000){IRQ=IRQ&0XFFFF0BFF;PRIORITY=PRIORITY|0B0100000000000;PRIORITY=PRIORITY&0XFFFFEFFF;break;}
            if(IRQ&0B0001000000000000){IRQ=IRQ&0XFFFF13FF;PRIORITY=PRIORITY&0XFFFFF7FF;PRIORITY=PRIORITY|0B1000000000000;break;}

            if(IRQ&0B1000000000000000){IRQ=IRQ&0XFFFF83FF;break;}
            break;
        case 0B1100000000000:
            if(IRQ&0B0000010000000000){IRQ=IRQ&0XFFFF07FF;break;}

            if(IRQ&0B0100000000000000){IRQ=IRQ&0XFFFF43FF;PRIORITY=PRIORITY&0XFFFFE7FF;break;}
            if(IRQ&0B0000100000000000){IRQ=IRQ&0XFFFF0BFF;PRIORITY=PRIORITY|0B0100000000000;PRIORITY=PRIORITY&0XFFFFEFFF;break;}
            if(IRQ&0B0001000000000000){IRQ=IRQ&0XFFFF13FF;PRIORITY=PRIORITY&0XFFFFF7FF;PRIORITY=PRIORITY|0B1000000000000;break;}
            if(IRQ&0B0010000000000000){IRQ=IRQ&0XFFFF23FF;PRIORITY=PRIORITY|0B1100000000000;break;}

            if(IRQ&0B1000000000000000){IRQ=IRQ&0XFFFF83FF;break;}
            break;
        default:
            break;
        }
    }else{
        switch (PRIORITY&0B1100000000000) {
        case 0B0000000000000:
            if(IRQ&0B0000010000000000){IRQ=IRQ&0XFFFF07FF;break;}

            if(IRQ&0B0000100000000000){IRQ=IRQ&0XFFFF0BFF;break;}
            if(IRQ&0B0001000000000000){IRQ=IRQ&0XFFFF13FF;break;}
            if(IRQ&0B0010000000000000){IRQ=IRQ&0XFFFF23FF;break;}
            if(IRQ&0B0100000000000000){IRQ=IRQ&0XFFFF43FF;break;}

            if(IRQ&0B1000000000000000){IRQ=IRQ&0XFFFF83FF;break;}
            break;
        case 0B0100000000000:
            if(IRQ&0B0000010000000000){IRQ=IRQ&0XFFFF07FF;break;}

            if(IRQ&0B0001000000000000){IRQ=IRQ&0XFFFF13FF;break;}
            if(IRQ&0B0010000000000000){IRQ=IRQ&0XFFFF23FF;break;}
            if(IRQ&0B0100000000000000){IRQ=IRQ&0XFFFF43FF;break;}
            if(IRQ&0B0000100000000000){IRQ=IRQ&0XFFFF0BFF;break;}

            if(IRQ&0B1000000000000000){IRQ=IRQ&0XFFFF83FF;break;}
            break;
        case 0B1000000000000:
            if(IRQ&0B0000010000000000){IRQ=IRQ&0XFFFF07FF;break;}

            if(IRQ&0B0010000000000000){IRQ=IRQ&0XFFFF23FF;break;}
            if(IRQ&0B0100000000000000){IRQ=IRQ&0XFFFF43FF;break;}
            if(IRQ&0B0000100000000000){IRQ=IRQ&0XFFFF0BFF;break;}
            if(IRQ&0B0001000000000000){IRQ=IRQ&0XFFFF13FF;break;}

            if(IRQ&0B1000000000000000){IRQ=IRQ&0XFFFF83FF;break;}
            break;
        case 0B1100000000000:
            if(IRQ&0B0000010000000000){IRQ=IRQ&0XFFFF07FF;break;}

            if(IRQ&0B0100000000000000){IRQ=IRQ&0XFFFF43FF;break;}
            if(IRQ&0B0000100000000000){IRQ=IRQ&0XFFFF0BFF;break;}
            if(IRQ&0B0001000000000000){IRQ=IRQ&0XFFFF13FF;break;}
            if(IRQ&0B0010000000000000){IRQ=IRQ&0XFFFF23FF;break;}

            if(IRQ&0B1000000000000000){IRQ=IRQ&0XFFFF83FF;break;}
            break;
        default:
            break;
        }
    }
    if(PRIORITY&1000){//3组轮转
        switch (PRIORITY&0B110000000000000) {
        case 0B000000000000000:
            if(IRQ&0B0000010000000000000000){IRQ=IRQ&0XF01FFFF;break;}// 13 14

            if(IRQ&0B0000100000000000000000){IRQ=IRQ&0XF02FFFF;PRIORITY=PRIORITY|0B010000000000000;PRIORITY=PRIORITY&0XFFBFFF;break;}
            if(IRQ&0B0001000000000000000000){IRQ=IRQ&0XF04FFFF;PRIORITY=PRIORITY&0XFFDFFF;PRIORITY=PRIORITY|0B100000000000000;break;}
            if(IRQ&0B0010000000000000000000){IRQ=IRQ&0XF08FFFF;PRIORITY=PRIORITY|0B110000000000000;break;}
            if(IRQ&0B0100000000000000000000){IRQ=IRQ&0XF10FFFF;PRIORITY=PRIORITY&0XFF9FFF;break;}

            if(IRQ&0B1000000000000000000000){IRQ=IRQ&0XF20FFFF;break;}
            break;
        case 0B010000000000000:
            if(IRQ&0B0000010000000000000000){IRQ=IRQ&0XF01FFFF;break;}

            if(IRQ&0B0001000000000000000000){IRQ=IRQ&0XF04FFFF;PRIORITY=PRIORITY&0XFFDFFF;PRIORITY=PRIORITY|0B100000000000000;break;}
            if(IRQ&0B0010000000000000000000){IRQ=IRQ&0XF08FFFF;PRIORITY=PRIORITY|0B110000000000000;break;}
            if(IRQ&0B0100000000000000000000){IRQ=IRQ&0XF10FFFF;PRIORITY=PRIORITY&0XFF9FFF;break;}
            if(IRQ&0B0000100000000000000000){IRQ=IRQ&0XF02FFFF;PRIORITY=PRIORITY|0B010000000000000;PRIORITY=PRIORITY&0XFFBFFF;break;}

            if(IRQ&0B1000000000000000000000){IRQ=IRQ&0XF20FFFF;break;}
            break;
        case 0B100000000000000:
            if(IRQ&0B0000010000000000000000){IRQ=IRQ&0XF01FFFF;break;}

            if(IRQ&0B0010000000000000000000){IRQ=IRQ&0XF08FFFF;PRIORITY=PRIORITY|0B110000000000000;break;}
            if(IRQ&0B0100000000000000000000){IRQ=IRQ&0XF10FFFF;PRIORITY=PRIORITY&0XFF9FFF;break;}
            if(IRQ&0B0000100000000000000000){IRQ=IRQ&0XF02FFFF;PRIORITY=PRIORITY|0B010000000000000;PRIORITY=PRIORITY&0XFFBFFF;break;}
            if(IRQ&0B0001000000000000000000){IRQ=IRQ&0XF04FFFF;PRIORITY=PRIORITY&0XFFDFFF;PRIORITY=PRIORITY|0B100000000000000;break;}

            if(IRQ&0B1000000000000000000000){IRQ=IRQ&0XF20FFFF;break;}
            break;
        case 0B110000000000000:
            if(IRQ&0B0000010000000000000000){IRQ=IRQ&0XF01FFFF;break;}

            if(IRQ&0B0100000000000000000000){IRQ=IRQ&0XF10FFFF;PRIORITY=PRIORITY&0XFF9FFF;break;}
            if(IRQ&0B0000100000000000000000){IRQ=IRQ&0XF02FFFF;PRIORITY=PRIORITY|0B010000000000000;PRIORITY=PRIORITY&0XFFBFFF;break;}
            if(IRQ&0B0001000000000000000000){IRQ=IRQ&0XF04FFFF;PRIORITY=PRIORITY&0XFFDFFF;PRIORITY=PRIORITY|0B100000000000000;break;}
            if(IRQ&0B0010000000000000000000){IRQ=IRQ&0XF08FFFF;PRIORITY=PRIORITY|0B110000000000000;break;}

            if(IRQ&0B1000000000000000000000){IRQ=IRQ&0XF20FFFF;break;}
            break;
        default:
            break;
        }
    }else{
        switch (PRIORITY&0B110000000000000) {
        case 0B000000000000000:
            if(IRQ&0B0000010000000000000000){IRQ=IRQ&0XF01FFFF;break;}

            if(IRQ&0B0000100000000000000000){IRQ=IRQ&0XF02FFFF;break;}
            if(IRQ&0B0001000000000000000000){IRQ=IRQ&0XF04FFFF;break;}
            if(IRQ&0B0010000000000000000000){IRQ=IRQ&0XF08FFFF;break;}
            if(IRQ&0B0100000000000000000000){IRQ=IRQ&0XF10FFFF;break;}

            if(IRQ&0B1000000000000000000000){IRQ=IRQ&0XF20FFFF;break;}
            break;
        case 0B010000000000000:
            if(IRQ&0B0000010000000000000000){IRQ=IRQ&0XF01FFFF;break;}

            if(IRQ&0B0001000000000000000000){IRQ=IRQ&0XF04FFFF;break;}
            if(IRQ&0B0010000000000000000000){IRQ=IRQ&0XF08FFFF;break;}
            if(IRQ&0B0100000000000000000000){IRQ=IRQ&0XF10FFFF;break;}
            if(IRQ&0B0000100000000000000000){IRQ=IRQ&0XF02FFFF;break;}

            if(IRQ&0B1000000000000000000000){IRQ=IRQ&0XF20FFFF;break;}
            break;
        case 0B100000000000000:
            if(IRQ&0B0000010000000000000000){IRQ=IRQ&0XF01FFFF;break;}

            if(IRQ&0B0010000000000000000000){IRQ=IRQ&0XF08FFFF;break;}
            if(IRQ&0B0100000000000000000000){IRQ=IRQ&0XF10FFFF;break;}
            if(IRQ&0B0000100000000000000000){IRQ=IRQ&0XF02FFFF;break;}
            if(IRQ&0B0001000000000000000000){IRQ=IRQ&0XF04FFFF;break;}

            if(IRQ&0B1000000000000000000000){IRQ=IRQ&0XF20FFFF;break;}
            break;
        case 0B110000000000000:
            if(IRQ&0B0000010000000000000000){IRQ=IRQ&0XF01FFFF;break;}

            if(IRQ&0B0100000000000000000000){IRQ=IRQ&0XF10FFFF;break;}
            if(IRQ&0B0000100000000000000000){IRQ=IRQ&0XF02FFFF;break;}
            if(IRQ&0B0001000000000000000000){IRQ=IRQ&0XF04FFFF;break;}
            if(IRQ&0B0010000000000000000000){IRQ=IRQ&0XF08FFFF;break;}

            if(IRQ&0B1000000000000000000000){IRQ=IRQ&0XF20FFFF;break;}
            break;
        default:
            break;
        }
    }
    if(PRIORITY&10000){//4组轮转
        switch (PRIORITY&0B11000000000000000) {
        case 0B00000000000000000:
            if(IRQ&0B0000010000000000000000000000){IRQ=IRQ&0XF07FFFFF;break;}

            if(IRQ&0B0000100000000000000000000000){IRQ=IRQ&0XF0BFFFFF;PRIORITY=PRIORITY|0B01000000000000000;PRIORITY=PRIORITY&0XFEFFFF;break;}
            if(IRQ&0B0001000000000000000000000000){IRQ=IRQ&0XF13FFFFF;PRIORITY=PRIORITY&0XFF7FFF;PRIORITY=PRIORITY|0B10000000000000000;break;}
            if(IRQ&0B0010000000000000000000000000){IRQ=IRQ&0XF23FFFFF;PRIORITY=PRIORITY|0B11000000000000000;break;}
            if(IRQ&0B0100000000000000000000000000){IRQ=IRQ&0XF43FFFFF;PRIORITY=PRIORITY&0XFE7FFF;break;}

            if(IRQ&0B1000000000000000000000000000){IRQ=IRQ&0XF83FFFFF;break;}
            break;
        case 0B01000000000000000:
            if(IRQ&0B0000010000000000000000000000){IRQ=IRQ&0XF07FFFFF;break;}

            if(IRQ&0B0001000000000000000000000000){IRQ=IRQ&0XF13FFFFF;PRIORITY=PRIORITY&0XFF7FFF;PRIORITY=PRIORITY|0B10000000000000000;break;}
            if(IRQ&0B0010000000000000000000000000){IRQ=IRQ&0XF23FFFFF;PRIORITY=PRIORITY|0B11000000000000000;break;}
            if(IRQ&0B0100000000000000000000000000){IRQ=IRQ&0XF43FFFFF;PRIORITY=PRIORITY&0XFE7FFF;break;}
            if(IRQ&0B0000100000000000000000000000){IRQ=IRQ&0XF0BFFFFF;PRIORITY=PRIORITY|0B01000000000000000;PRIORITY=PRIORITY&0XFEFFFF;break;}

            if(IRQ&0B1000000000000000000000000000){IRQ=IRQ&0XF83FFFFF;break;}
            break;
        case 0B10000000000000000:
            if(IRQ&0B0000010000000000000000000000){IRQ=IRQ&0XF07FFFFF;break;}

            if(IRQ&0B0010000000000000000000000000){IRQ=IRQ&0XF23FFFFF;PRIORITY=PRIORITY|0B11000000000000000;break;}
            if(IRQ&0B0100000000000000000000000000){IRQ=IRQ&0XF43FFFFF;PRIORITY=PRIORITY&0XFE7FFF;break;}
            if(IRQ&0B0000100000000000000000000000){IRQ=IRQ&0XF0BFFFFF;PRIORITY=PRIORITY|0B01000000000000000;PRIORITY=PRIORITY&0XFEFFFF;break;}
            if(IRQ&0B0001000000000000000000000000){IRQ=IRQ&0XF13FFFFF;PRIORITY=PRIORITY&0XFF7FFF;PRIORITY=PRIORITY|0B10000000000000000;break;}

            if(IRQ&0B1000000000000000000000000000){IRQ=IRQ&0XF83FFFFF;break;}
            break;
        case 0B11000000000000000:
            if(IRQ&0B0000010000000000000000000000){IRQ=IRQ&0XF07FFFFF;break;}

            if(IRQ&0B0100000000000000000000000000){IRQ=IRQ&0XF43FFFFF;PRIORITY=PRIORITY&0XFE7FFF;break;}
            if(IRQ&0B0000100000000000000000000000){IRQ=IRQ&0XF0BFFFFF;PRIORITY=PRIORITY|0B01000000000000000;PRIORITY=PRIORITY&0XFEFFFF;break;}
            if(IRQ&0B0001000000000000000000000000){IRQ=IRQ&0XF13FFFFF;PRIORITY=PRIORITY&0XFF7FFF;PRIORITY=PRIORITY|0B10000000000000000;break;}
            if(IRQ&0B0010000000000000000000000000){IRQ=IRQ&0XF23FFFFF;PRIORITY=PRIORITY|0B11000000000000000;break;}

            if(IRQ&0B1000000000000000000000000000){IRQ=IRQ&0XF83FFFFF;break;}
            break;
        default:
            break;
        }
    }else{
        switch (PRIORITY&0B11000000000000000) {
        case 0B00000000000000000:
            if(IRQ&0B0000010000000000000000000000){IRQ=IRQ&0XF07FFFFF;break;}

            if(IRQ&0B0000100000000000000000000000){IRQ=IRQ&0XF0BFFFFF;break;}
            if(IRQ&0B0001000000000000000000000000){IRQ=IRQ&0XF13FFFFF;break;}
            if(IRQ&0B0010000000000000000000000000){IRQ=IRQ&0XF23FFFFF;break;}
            if(IRQ&0B0100000000000000000000000000){IRQ=IRQ&0XF43FFFFF;break;}

            if(IRQ&0B1000000000000000000000000000){IRQ=IRQ&0XF83FFFFF;break;}
            break;
        case 0B01000000000000000:
            if(IRQ&0B0000010000000000000000000000){IRQ=IRQ&0XF07FFFFF;break;}

            if(IRQ&0B0001000000000000000000000000){IRQ=IRQ&0XF13FFFFF;break;}
            if(IRQ&0B0010000000000000000000000000){IRQ=IRQ&0XF23FFFFF;break;}
            if(IRQ&0B0100000000000000000000000000){IRQ=IRQ&0XF43FFFFF;break;}
            if(IRQ&0B0000100000000000000000000000){IRQ=IRQ&0XF0BFFFFF;break;}

            if(IRQ&0B1000000000000000000000000000){IRQ=IRQ&0XF83FFFFF;break;}
            break;
        case 0B10000000000000000:
            if(IRQ&0B0000010000000000000000000000){IRQ=IRQ&0XF07FFFFF;break;}

            if(IRQ&0B0010000000000000000000000000){IRQ=IRQ&0XF23FFFFF;break;}
            if(IRQ&0B0100000000000000000000000000){IRQ=IRQ&0XF43FFFFF;break;}
            if(IRQ&0B0000100000000000000000000000){IRQ=IRQ&0XF0BFFFFF;break;}
            if(IRQ&0B0001000000000000000000000000){IRQ=IRQ&0XF13FFFFF;break;}

            if(IRQ&0B1000000000000000000000000000){IRQ=IRQ&0XF83FFFFF;break;}
            break;
        case 0B11000000000000000:
            if(IRQ&0B0000010000000000000000000000){IRQ=IRQ&0XF07FFFFF;break;}

            if(IRQ&0B0100000000000000000000000000){IRQ=IRQ&0XF43FFFFF;break;}
            if(IRQ&0B0000100000000000000000000000){IRQ=IRQ&0XF0BFFFFF;break;}
            if(IRQ&0B0001000000000000000000000000){IRQ=IRQ&0XF13FFFFF;break;}
            if(IRQ&0B0010000000000000000000000000){IRQ=IRQ&0XF23FFFFF;break;}

            if(IRQ&0B1000000000000000000000000000){IRQ=IRQ&0XF83FFFFF;break;}
            break;
        default:
            break;
        }

    }
    if(PRIORITY&100000){//5组轮转
        switch (PRIORITY&0B1100000000000000000) {
        case 0B0000000000000000000:
            if(IRQ&0B00010000000000000000000000000000){IRQ=IRQ&0X1FFFFFFF;PRIORITY=PRIORITY|0B0100000000000000000;PRIORITY=PRIORITY&0XFBFFFF;break;}
            if(IRQ&0B00100000000000000000000000000000){IRQ=IRQ&0X2FFFFFFF;PRIORITY=PRIORITY&0XFDFFFF;PRIORITY=PRIORITY|0B1000000000000000000;break;}
            if(IRQ&0B01000000000000000000000000000000){IRQ=IRQ&0X4FFFFFFF;PRIORITY=PRIORITY|0B1100000000000000000;break;}
            if(IRQ&0B10000000000000000000000000000000){IRQ=IRQ&0X8FFFFFFF;PRIORITY=PRIORITY&0XF9FFFF;break;}
            break;
        case 0B0100000000000000000:                   
            if(IRQ&0B00100000000000000000000000000000){IRQ=IRQ&0X2FFFFFFF;PRIORITY=PRIORITY&0XFDFFFF;PRIORITY=PRIORITY|0B1000000000000000000;break;}
            if(IRQ&0B01000000000000000000000000000000){IRQ=IRQ&0X4FFFFFFF;PRIORITY=PRIORITY|0B1100000000000000000;break;}
            if(IRQ&0B10000000000000000000000000000000){IRQ=IRQ&0X8FFFFFFF;PRIORITY=PRIORITY&0XF9FFFF;break;}
            if(IRQ&0B00010000000000000000000000000000){IRQ=IRQ&0X1FFFFFFF;PRIORITY=PRIORITY|0B0100000000000000000;PRIORITY=PRIORITY&0XFBFFFF;break;}
            break;
        case 0B1000000000000000000:                   
            if(IRQ&0B01000000000000000000000000000000){IRQ=IRQ&0X4FFFFFFF;PRIORITY=PRIORITY|0B1100000000000000000;break;}
            if(IRQ&0B10000000000000000000000000000000){IRQ=IRQ&0X8FFFFFFF;PRIORITY=PRIORITY&0XF9FFFF;break;}
            if(IRQ&0B00010000000000000000000000000000){IRQ=IRQ&0X1FFFFFFF;PRIORITY=PRIORITY|0B0100000000000000000;PRIORITY=PRIORITY&0XFBFFFF;break;}
            if(IRQ&0B00100000000000000000000000000000){IRQ=IRQ&0X2FFFFFFF;PRIORITY=PRIORITY&0XFDFFFF;PRIORITY=PRIORITY|0B1000000000000000000;break;}
            break;
        case 0B1100000000000000000:                       
            if(IRQ&0B10000000000000000000000000000000){IRQ=IRQ&0X8FFFFFFF;PRIORITY=PRIORITY&0XF9FFFF;break;}
            if(IRQ&0B00010000000000000000000000000000){IRQ=IRQ&0X1FFFFFFF;PRIORITY=PRIORITY|0B0100000000000000000;PRIORITY=PRIORITY&0XFBFFFF;break;}
            if(IRQ&0B00100000000000000000000000000000){IRQ=IRQ&0X2FFFFFFF;PRIORITY=PRIORITY&0XFDFFFF;PRIORITY=PRIORITY|0B1000000000000000000;break;}
            if(IRQ&0B01000000000000000000000000000000){IRQ=IRQ&0X4FFFFFFF;PRIORITY=PRIORITY|0B1100000000000000000;break;}
            break;
        default:
            break;
        }
    }else{
        switch (PRIORITY&0B1100000000000000000){
        case 0B0000000000000000000:
            if(IRQ&0B00010000000000000000000000000000){IRQ=IRQ&0X1FFFFFFF;break;}
            if(IRQ&0B00100000000000000000000000000000){IRQ=IRQ&0X2FFFFFFF;break;}
            if(IRQ&0B01000000000000000000000000000000){IRQ=IRQ&0X4FFFFFFF;break;}
            if(IRQ&0B10000000000000000000000000000000){IRQ=IRQ&0X8FFFFFFF;break;}
            break;
        case 0B0100000000000000000:
            if(IRQ&0B00100000000000000000000000000000){IRQ=IRQ&0X2FFFFFFF;break;}
            if(IRQ&0B01000000000000000000000000000000){IRQ=IRQ&0X4FFFFFFF;break;}
            if(IRQ&0B10000000000000000000000000000000){IRQ=IRQ&0X8FFFFFFF;break;}
            if(IRQ&0B00010000000000000000000000000000){IRQ=IRQ&0X1FFFFFFF;break;}
            break;
        case 0B1000000000000000000:
            if(IRQ&0B01000000000000000000000000000000){IRQ=IRQ&0X4FFFFFFF;break;}
            if(IRQ&0B10000000000000000000000000000000){IRQ=IRQ&0X8FFFFFFF;break;}
            if(IRQ&0B00010000000000000000000000000000){IRQ=IRQ&0X1FFFFFFF;break;}
            if(IRQ&0B00100000000000000000000000000000){IRQ=IRQ&0X2FFFFFFF;break;}
            break;
        case 0B1100000000000000000:
            if(IRQ&0B10000000000000000000000000000000){IRQ=IRQ&0X8FFFFFFF;break;}
            if(IRQ&0B00010000000000000000000000000000){IRQ=IRQ&0X1FFFFFFF;break;}
            if(IRQ&0B00100000000000000000000000000000){IRQ=IRQ&0X2FFFFFFF;break;}
            if(IRQ&0B01000000000000000000000000000000){IRQ=IRQ&0X4FFFFFFF;break;}
            break;
        default:
            break;
        }
    }
    if(PRIORITY&1000000){//6组轮转
        switch (PRIORITY&0B110000000000000000000) {
        case 0B000000000000000000000:
            if(IRQ&0B1111){IRQ=IRQ&0B1111;break;}

            if(IRQ&0B1111110000){IRQ=IRQ&0B1111110000;break;}
            if(IRQ&0B1111110000000000){IRQ=IRQ&0B1111110000000000;break;}
            if(IRQ&0B1111110000000000000000){IRQ=IRQ&0B1111110000000000000000;break;}
            if(IRQ&0B1111110000000000000000000000){IRQ=IRQ&0B1111110000000000000000000000;break;}

            if(IRQ&0B11110000000000000000000000000000){IRQ=IRQ&0XF0000000;break;}
            break;
        case 0B010000000000000000000:
            if(IRQ&0B1111){IRQ=IRQ&0B1111;break;}

            if(IRQ&0B1111110000000000){IRQ=IRQ&0B1111110000000000;break;}
            if(IRQ&0B1111110000000000000000){IRQ=IRQ&0B1111110000000000000000;break;}
            if(IRQ&0B1111110000000000000000000000){IRQ=IRQ&0B1111110000000000000000000000;break;}
            if(IRQ&0B1111110000){IRQ=IRQ&0B1111110000;break;}

            if(IRQ&0B11110000000000000000000000000000){IRQ=IRQ&0XF0000000;break;}
            break;
        case 0B100000000000000000000:
            if(IRQ&0B1111){IRQ=IRQ&0B1111;break;}

            if(IRQ&0B1111110000000000000000){IRQ=IRQ&0B1111110000000000000000;break;}
            if(IRQ&0B1111110000000000000000000000){IRQ=IRQ&0B1111110000000000000000000000;break;}
            if(IRQ&0B1111110000){IRQ=IRQ&0B1111110000;break;}
            if(IRQ&0B1111110000000000){IRQ=IRQ&0B1111110000000000;break;}

            if(IRQ&0B11110000000000000000000000000000){IRQ=IRQ&0XF0000000;break;}
            break;
        case 0B110000000000000000000:
            if(IRQ&0B1111){IRQ=IRQ&0B1111;break;}

            if(IRQ&0B1111110000000000000000000000){IRQ=IRQ&0B1111110000000000000000000000;break;}
            if(IRQ&0B1111110000){IRQ=IRQ&0B1111110000;break;}
            if(IRQ&0B1111110000000000){IRQ=IRQ&0B1111110000000000;break;}
            if(IRQ&0B1111110000000000000000){IRQ=IRQ&0B1111110000000000000000;break;}

            if(IRQ&0B11110000000000000000000000000000){IRQ=IRQ&0XF0000000;break;}
            break;
        default:
            break;
        }
    }else{
        switch (PRIORITY&0B110000000000000000000) {
        case 0B000000000000000000000:
            if(IRQ&0B1111){IRQ=IRQ&0B1111;break;}

            if(IRQ&0B1111110000){IRQ=IRQ&0B1111110000;break;}
            if(IRQ&0B1111110000000000){IRQ=IRQ&0B1111110000000000;break;}
            if(IRQ&0B1111110000000000000000){IRQ=IRQ&0B1111110000000000000000;break;}
            if(IRQ&0B1111110000000000000000000000){IRQ=IRQ&0B1111110000000000000000000000;break;}

            if(IRQ&0B11110000000000000000000000000000){IRQ=IRQ&0XF0000000;break;}
            break;
        case 0B010000000000000000000:
            if(IRQ&0B1111){IRQ=IRQ&0B1111;break;}

            if(IRQ&0B1111110000000000){IRQ=IRQ&0B1111110000000000;break;}
            if(IRQ&0B1111110000000000000000){IRQ=IRQ&0B1111110000000000000000;break;}
            if(IRQ&0B1111110000000000000000000000){IRQ=IRQ&0B1111110000000000000000000000;break;}
            if(IRQ&0B1111110000){IRQ=IRQ&0B1111110000;break;}

            if(IRQ&0B11110000000000000000000000000000){IRQ=IRQ&0XF0000000;break;}
            break;
        case 0B100000000000000000000:
            if(IRQ&0B1111){IRQ=IRQ&0B1111;break;}

            if(IRQ&0B1111110000000000000000){IRQ=IRQ&0B1111110000000000000000;break;}
            if(IRQ&0B1111110000000000000000000000){IRQ=IRQ&0B1111110000000000000000000000;break;}
            if(IRQ&0B1111110000){IRQ=IRQ&0B1111110000;break;}
            if(IRQ&0B1111110000000000){IRQ=IRQ&0B1111110000000000;break;}

            if(IRQ&0B11110000000000000000000000000000){IRQ=IRQ&0XF0000000;break;}
            break;
        case 0B110000000000000000000:
            if(IRQ&0B1111){IRQ=IRQ&0B1111;break;}

            if(IRQ&0B1111110000000000000000000000){IRQ=IRQ&0B1111110000000000000000000000;break;}
            if(IRQ&0B1111110000){IRQ=IRQ&0B1111110000;break;}
            if(IRQ&0B1111110000000000){IRQ=IRQ&0B1111110000000000;break;}
            if(IRQ&0B1111110000000000000000){IRQ=IRQ&0B1111110000000000000000;break;}

            if(IRQ&0B11110000000000000000000000000000){IRQ=IRQ&0XF0000000;break;}
            break;
        default:
            break;
        }
    }
    INTOFFSET=INTPND=IRQ;
    memcontrol(rPRIORITY,false,PRIORITY,4);
    memcontrol(rINTPND,false,INTPND,4);
    memcontrol(rINTOFFSET,false,INTOFFSET,4);
    if(INTPND){
        R_IRQ[14]=PC;
        SPSR_IRQ=CPSR;
        CPSR=CPSR&0XFFFFFFF2;
        CPSR=CPSR|0B10010;
        PC=0X18;
    }
}
